Thread synchronization in a multi-thread network communications processor  architecture

ABSTRACT

Described embodiments provide a packet classifier for a network processor that generates tasks corresponding to each received packet. The packet classifier includes a scheduler to generate a thread of contexts for each task received by the packet classifier from a plurality of processing modules of the network processor. The scheduler includes one or more output queues to temporarily store contexts. Each thread corresponds to an order of instructions applied to the corresponding packet, and includes an identifier of a corresponding one of the output queues. The scheduler sends the contexts to a multi-thread instruction engine that processes the threads. An arbiter selects one of the output queues in order to provide output packets to the multi-thread instruction engine, the output packets associated with a corresponding thread of contexts. Each output queue transmits output packets corresponding to a given thread contiguously in the order in which the threads started.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application claims the benefit of the filing date of U.S.provisional application Nos. 61/313,399 filed Mar. 12, 2010 and61/313,219 filed Mar. 12, 2010, the teachings of which are incorporatedherein in their entireties by reference.

This application is a continuation-in-part, and claims the benefit ofthe filing date, of U.S. patent application Ser. No. 12/782,379 filedMay 18, 2010, Ser No. 12/782,393 filed May 18, 2010, now U.S. Pat. No.8,255,644 and Ser. No. 12/782,411 filed May 18, 2010, now U.S. Pat. No.8,407,707 the teachings of which are incorporated herein in theirentireties by reference.

The subject matter of this application is related to U.S. patentapplication Ser. No. 12/430,438 filed Apr. 27, 2009, Ser. No. 12/729,226filed Mar. 22, 2010, Ser. No. 12/729,231 filed Mar. 22, 2010, Ser. No.12/963,895 filed Dec. 9, 2010, Ser. No. 12/971,742 filed Dec. 17, 2010,Ser. No. 12/974,477 filed Dec. 21, 2010, Ser. No. 12/975,823 filed Dec.22, 2010, Ser. No. 12/976,045 filed Dec. 22, 2010, and Ser. No.12/976,228 filed Dec. 22, 2010, the teachings of which are incorporatedherein in their entireties by reference.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention relates to communication systems, in particular,to an accelerated processor architecture for network communications.

2. Description of the Related Art

Network processors are generally used for analyzing and processingpacket data for routing and switching packets in a variety ofapplications, such as network surveillance, video transmission, protocolconversion, voice processing, and internet traffic routing. Early typesof network processors were based on software-based approaches withgeneral-purpose processors, either singly or in a multi-coreimplementation, but such software-based approaches are slow. Further,increasing the number of general-purpose processors had diminishingperformance improvements, or might actually slow down overall networkprocessor throughput. Newer designs add hardware accelerators to offloadcertain tasks from the general-purpose processors, such asencryption/decryption, packet data inspections, and the like. Thesenewer network processor designs are traditionally implemented witheither i) a non-pipelined architecture or ii) a fixed pipelinearchitecture.

In a typical non-pipelined architecture, general-purpose processors areresponsible for each action taken by acceleration functions. Anon-pipelined architecture provides great flexibility in that thegeneral-purpose processors can make decisions on a dynamic,packet-by-packet basis, thus providing data packets only to theaccelerators or other processors that are required to process eachpacket. However, significant software overhead is involved in thosecases where multiple accelerator actions might occur in sequence.

In a typical fixed-pipeline architecture, packet data flows through thegeneral-purpose processors and/or accelerators in a fixed sequenceregardless of whether a particular processor or accelerator is requiredto process a given packet. This fixed sequence might add significantoverhead to packet processing and has limited flexibility to handle newprotocols, limiting the advantage provided by the using accelerators.

Read latency and overall read throughput to storage devices withsequential access penalties, particularly memories external to a systemon chip (SoC), can be performance bottlenecks for the SoC. For example,an external memory might include two or more substructures (e.g.,multiple banks of DRAM). In such a system, a latency penalty might beincurred for sequential read requests to the same memory substructure.Several mechanisms have been developed for addressing this bottleneck.One mechanism queues read operations or requests (“read requests”)destined for each individual memory substructure and then selects readrequests for non-busy substructures from one or more queues. Queuingworks well when these read requests are spread evenly among the memorysubstructures, but fails if all the read requests target a particularsubstructure. Another mechanism duplicates the entire data structuremultiple times with a number of copies and then selects a non-busysubstructure as the target of the read request. This mechanism workswell and overcomes some of the shortcomings of the other mechanism, butthe amount of data stored by the memory is reduced by i) the inverse ofthe number of copies regardless of whether or not all of the databenefited from the duplication, or ii) the memory required increases asa multiple of the number of copies required.

SUMMARY OF THE INVENTION

This Summary is provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify key features oressential features of the claimed subject matter, nor is it intended tobe used to limit the scope of the claimed subject matter.

Described embodiments provide a packet classifier for a networkprocessor that generates tasks corresponding to each received packet.The packet classifier includes a scheduler to generate a thread ofcontexts for each task received by the packet classifier from aplurality of processing modules of the network processor. The schedulerincludes one or more output queues to temporarily store contexts. Eachthread corresponds to an order of instructions applied to thecorresponding packet, and includes an identifier of a corresponding oneof the output queues. The scheduler sends the contexts to a multi-threadinstruction engine that processes the threads. An arbiter selects one ofthe output queues in order to provide output packets to the multi-threadinstruction engine, the output packets associated with a correspondingthread of contexts. Each output queue transmits output packetscorresponding to a given thread contiguously in the order in which thethreads started.

BRIEF DESCRIPTION OF THE DRAWINGS

Other aspects, features, and advantages of the present invention willbecome more fully apparent from the following detailed description, theappended claims, and the accompanying drawings in which like referencenumerals identify similar or identical elements.

FIG. 1 shows a block diagram of a network processor operating inaccordance with exemplary embodiments of the present invention;

FIG. 2 shows a block diagram of a modular packet processor submodule ofthe network processor of FIG. 1;

FIG. 3 shows a block diagram of an exemplary memory interface of themodular packet processor of FIG. 2;

FIG. 4 shows a first exemplary tree memory addressing algorithm of thememory interface of FIG. 3;

FIG. 5 shows a second exemplary tree memory addressing algorithm of thememory interface of FIG. 3;

FIG. 6 shows a third exemplary tree memory addressing algorithm of thememory interface of FIG. 3;

FIG. 7 shows a block diagram of an exemplary thread information flowfrom input packets to output packets in accordance with exemplaryembodiments of the present invention;

FIG. 8 shows a block diagram of an output queue system in accordancewith exemplary embodiments of the present invention;

FIG. 9 shows an exemplary process diagram for moving a non-empty threadto a non-empty one of the output queues of FIG. 8;

FIG. 10 shows an exemplary process diagram for moving a non-empty threadto an empty one of the output queues of FIG. 8;

FIG. 11 shows an exemplary process diagram for moving an empty thread toa non-empty one of the output queues of FIG. 8;

FIG. 12 shows an exemplary process diagram for moving an empty thread toan empty one of the output queues of FIG. 8;

FIG. 13 shows a flow diagram of a breakpoint process in accordance withexemplary embodiments of the present invention;

FIG. 14 shows a block diagram of a thread status data structure inaccordance with embodiments of the present invention;

FIG. 15 shows a block diagram of a Thread Scheduling Manager (TSM) andone or more Event Scheduling Modules (ESMs) of the modular packetprocessor of FIG. 2; and

FIG. 16 shows a block diagram of an exemplary system timing for a systememploying one or more ESMs of FIG. 15.

DETAILED DESCRIPTION

Described embodiments provide a packet classifier for a networkprocessor that generates tasks corresponding to each received packet.The packet classifier includes a scheduler to generate a thread ofcontexts for each task received by the packet classifier from aplurality of processing modules of the network processor. The schedulerincludes one or more output queues to temporarily store contexts. Eachthread corresponds to an order of instructions applied to thecorresponding packet, and includes an identifier of a corresponding oneof the output queues. The scheduler sends the contexts to a multi-threadinstruction engine that processes the threads. An arbiter selects one ofthe output queues in order to provide output packets to the multi-threadinstruction engine, the output packets associated with a correspondingthread of contexts. Each output queue transmits output packetscorresponding to a given thread contiguously in the order in which thethreads started.

Table 1 defines a list of acronyms employed throughout thisspecification as an aid to understanding the described embodiments ofthe present invention:

TABLE 1 USB Universal Serial Bus FIFO First-In, First-Out SATA SerialAdvanced I/O Input/Output Technology Attachment SCSI Small ComputerSystem DDR Double Data Rate Interface SAS Serial Attached SCSI DRAMDynamic Random Access Memory PCI-E Peripheral Component MMB MemoryManager Block Interconnect Express SoC System-on-Chip μP MicroprocessorAXI Advanced eXtensible PLB Processor Local Bus Interface AMBA AdvancedMicrocontroller MPP Modular Packet Bus Architecture Processor PAB PacketAssembly Block AAL5 ATM Adaptation Layer 5 MTM Modular Traffic ManagerSED Stream Editor NMSI Network Processor Memory CMSI Client MemorySystem System Interface Interface CNAL CMSI - NMSI Adaption THID ThreadIdentifier Layer DBC Data Buffer Controller PQM Pre-Queue Modifier HEHash Engine FBI Function Bus Interface SENG State Engine CCLClassification Completion List TID Task Identifier SEM Semaphore EngineSCH Scheduler PCM Per Context Memory SPP Security Protocol Processor PDUProtocol Data Unit TIL Task Input Logic PIC Packet Integrity Checker TCPTransmission Control CRC Cyclic Redundancy Protocol Check MTIEMulti-Thread Instruction Engine IP Internet Protocol UDP User DatagramProtocol

FIG. 1 shows a block diagram of an exemplary network processor system(network processor 100) implemented as a system-on-chip (SoC). Networkprocessor 100 might be used for processing data packets, performingprotocol conversion, encrypting and decrypting data packets, or thelike. As shown in FIG. 1, network processor 100 includes on-chip sharedmemory 112, one or more input-output (I/O) interfaces collectively shownas I/O interface 104, one or more microprocessor (μmP) cores 106 ₁-106_(M), and one or more hardware accelerators 108 ₁-108 _(N), where M andN are integers greater than or equal to 1. Network processor 100 alsoincludes external memory interface 114 for communication with externalmemory 116. External memory 116 might typically be implemented as adynamic random-access memory (DRAM), such as a double-data-rate three(DDR-3) DRAM, for off-chip storage of data. In some embodiments, such asshown in FIG. 1, each of the one or more I/O interfaces, μP cores andhardware accelerators might be coupled to switch 110 that is coupled toshared memory 112. Switch 110 might be implemented as a non-blockingcrossbar switch such as described in related U.S. patent applicationsSer. No. 12/430,438 filed Apr. 27, 2009, Ser. No. 12/729,226 filed Mar.22, 2010, and Ser. No. 12/729,231 filed Mar. 22, 2010.

I/O interface 104 might typically be implemented as hardware thatconnects network processor 100 to one or more external devices throughI/O communication link 102. I/O communication link 102 might generallybe employed for communication with one or more external devices, such asa computer system or a networking device, that interface with networkprocessor 100. I/O communication link 102 might be a custom-designedcommunication link, or might conform to a standard communicationprotocol such as, for example, a Small Computer System Interface(“SCSI”) protocol bus, a Serial Attached SCSI (“SAS”) protocol bus, aSerial Advanced Technology Attachment (“SATA”) protocol bus, a UniversalSerial Bus (“USB”), an Ethernet link, an IEEE 802.11 link, an IEEE802.15 link, an IEEE 802.16 link, a Peripheral Component InterconnectExpress (“PCI-E”) link, a Serial Rapid I/O (“SRIO”) link, or any otherinterface link. Received packets are preferably placed in a buffer inshared memory 112 by transfer between I/O interface 104 and sharedmemory 112 through switch 110.

In embodiments of the present invention, shared memory 112 is aconventional memory operating as a cache that might be allocated and/orsubdivided. For example, shared memory 112 might include one or moreFIFO queues that might be dynamically allocated to the various μP cores106 and hardware accelerators 108. External memory interface 114 couplesshared memory 112 to external memory 116 to provide off-chip storage ofdata not needed by the various μP cores 106 and hardware accelerators108 to free space in shared memory 112. The μP cores and hardwareaccelerators might interact with each other as described in related U.S.patent applications Ser. Nos. 12/782,379, 12/782,393, and 12/782,411,all filed May 18, 2010, for example, by one or more communication busrings that pass “tasks” from a source core to a destination core. Asdescribed herein, tasks are instructions to the destination core toperform certain functions, and a task might contain address pointers todata stored in shared memory 112.

Network processor 100 might typically receive data packets from one ormore source devices, perform processing operations for the received datapackets, and transmit data packets out to one or more destinationdevices. As shown in FIG. 1, one or more data packets are transmittedfrom a transmitting device (not shown) to network processor 100, via I/Ocommunication link 102. Network processor 100 might receive data packetsfrom one or more active data streams concurrently from I/O communicationlink 102. I/O interface 104 might parse the received data packet andprovide the received data packet, via switch 110, to a buffer in sharedmemory 112. I/O interface 104 provides various types of I/O interfacefunctions and, in exemplary embodiments described herein, is acommand-driven hardware accelerator that connects network processor 100to external devices. Received packets are preferably placed in sharedmemory 112 and then one or more corresponding tasks are generated.Transmitted packets are preferably received for a task and transmittedexternally. Exemplary I/O interfaces include Ethernet I/O adaptersproviding integrity checks of incoming data. The I/O adapters might alsoprovide timestamp data for received and transmitted packets that mightbe used to implement features such as timing over packet (e.g.,specified in the standard recommendations of IEEE 1588). In alternativeembodiments, I/O interface 104 might be implemented as input (receive)only or output (transmit) only interfaces.

The various μP cores 106 and hardware accelerators 108 of networkprocessor 100 might include several exemplary types of processors oraccelerators. For example, the various μP cores 106 and hardwareaccelerators 108 might include, for example, a Modular Packet Processor(MPP), a Packet Assembly Block (PAB), a Modular Traffic Manager (MTM), aMemory Management Block (MMB), a Stream Editor (SED), a SecurityProtocol Processor (SPP), a Regular Expression (RegEx) engine, and otherspecial-purpose modules.

The MTM is a software-driven accelerator that provides packet schedulingfor up to six levels of scheduling hierarchy. The MTM might supportmillions of queues and schedulers (enabling per flow queuing ifdesired). The MTM might provide support for shaping and scheduling withsmooth deficit weighed round robin (SDWRR) for every queue andscheduler. The MTM might also support multicasting. Each copy of apacket is scheduled independently and traverses down different virtualpipelines enabling multicast with independent encapsulations or anyother processing. The MTM might also contain a special purpose processorthat can be used for fine-grained control of scheduling decisions. TheMTM might be used to make discard decisions as well as scheduling andshaping decisions.

The SED is a software-driven accelerator that allows for editing ofpackets. The SED performs packet editing functions that might includeadding and modifying packet headers as well as fragmenting or segmentingdata (e.g., IP fragmentation). The SED receives packet data as well asparameters from tasks and a task specified per-flow state. The output ofthe SED becomes the outgoing packet data and can also update taskparameters.

The RegEx engine is a packet search engine for state-based cross-packetpattern matching. The RegEx engine is multi-threaded accelerator. Anexemplary RegEx engine might be implemented such as described in U.S.Pat. No. 7,439,652 or U.S. Patent Application Publication No.2008/0270342, both of which are incorporated by reference herein intheir entireties.

The SPP provides encryption/decryption capabilities and is acommand-driven hardware accelerator, preferably having the flexibilityto handle protocol variability and changing standards with the abilityto add security protocols with firmware upgrades. The ciphers andintegrity (hash) functions might be implemented in hardware. The SPP hasa multiple ordered task queue mechanism, discussed in more detail below,that is employed for load balancing across the threads.

The MMB allocates and frees memory resources in shared memory 112.Memory is allocated for such applications as task FIFO storage, packetdata storage, hash-table collision handling, timer event management, andtraffic manager queues. The MMB provides reference counts to each blockof memory within shared memory 112. Multiple reference counts allow formore efficient storage of information, such as multicast traffic (datato be sent to multiple destinations) or for retransmission. Multiplereference counts remove the need for replicating the data each time thedata is needed. The MMB preferably tracks the memory allocations using astack-based approach since a memory block recently released ispreferably the next block to be allocated for a particular task,reducing cache trashing and cache tracking overhead.

The PAB is a command driven hardware accelerator providing a holdingbuffer with packet assembly, transmit, retransmit, and deletecapabilities. An incoming task to the PAB can specify to insert/extractdata from anywhere in any assembly buffer. Gaps are supported in anybuffer. Locations to insert and extract can be specified to the bitlevel. Exemplary traditional packet reassembly functions might besupported, such as IP defragmentation. The PAB might also supportgeneralized holding buffer and sliding window protocoltransmit/retransmit buffering, providing an offload for features likeTCP origination, termination, and normalization.

The MPP is a multi-threaded special purpose processor that provides treebased longest prefix and access control list classification. The MPPalso has a hardware hash-based classification capability with fullhardware management of hash-table additions, deletions, and collisionhandling. Optionally associated with each hash entry is a timer thatmight be used under software control for tasks such as connectiontimeout and retransmission timing. The MPP contains a statistics andstate management engine, which when combined with the hash table andtimer facilities, provides support for state-based protocol processing.The MPP might support millions of flows, limited only by the amount ofDRAM capacity assigned to the functions. The MPP architecture might beable to store all per thread states in memory instead of in registerfiles.

FIG. 2 shows a block diagram of an exemplary MPP 200, in accordance withembodiments of the present invention. MPP 200 might receive an inputtask from any μP core or accelerator (e.g., μP cores 106 or accelerators108) of network processor 100. MPP 200 performs operations specified bythe input task on a data packet stored in at least one of shared memory112 and external memory 116. When MPP 200 is finished operating on thedata packet, MPP 200 might generate an output task to another μP core oraccelerator of network processor 100, for example, a next μP core oraccelerator specified for a given virtual flow identifier.

As described herein, MPP 200 might generally be employed as a packetclassification engine in network processor 100. In general, packetclassification categorizes packets into classes, for example, based onport number or protocol. Each resulting packet class might be treateddifferently to control packet flow, for example, each packet class mightbe subject to a different rate limit or prioritized differently relativeto other packet classes. Classification is achieved by various means.Matching bit patterns of data to those of known protocols is a simple,yet widely-used technique. More advanced traffic classificationtechniques rely on statistical analysis of attributes such as bytefrequencies, packet sizes and packet inter-arrival times. Uponclassifying a traffic flow using a particular protocol, a predeterminedpolicy can be applied to it and other flows to either guarantee acertain quality (as with VoIP or media streaming service) or to providebest-effort delivery.

As shown in FIG. 2, and as will be described, packet classificationmight be performed by Multi-thread Instruction Engine (MTIE) 214 of MPP200. Packet (also Protocol Data Unit or PDU) data modification might becarried out by Pre-Queue Modifier (PQM) 208. A packet integrity checkmight typically be carried out by Packet Integrity Checker (PIC) 210,such as determining that a packet is properly formed according to agiven protocol. PIC 210 might, for example, implement various CRC andchecksum functions of MPP 200. Interface to communication interface 202might provide a standard interface between MPP 200 and chip levelconnections to external modules of network processor 100, for example byone or more ring communication buses.

Semaphore Engine (SEM) 222 implements semaphore logic in MPP 200, andmight support up to 1024 logical semaphores, which might correspond to 4physical semaphores, each corresponding to 256 logical semaphores.Semaphores are used to manage atomic access to a hardware resource ofnetwork processor 100 and MPP 200. For example, for a context thread toutilize an instance of a hardware resource, the context thread mighthave to reserve a semaphore for that resource. A context might beallowed to have up to 4 outstanding physical semaphores. Semaphores areallocated and released by SEM 222 based on function calls received byfunction bus 212. SEM 222 might support ordered and unordered semaphorecalls.

Hash table operations might be carried out by Hash Engine (HE) 220. HE220 implements hash engine functionality in MPP 200. HE 220 receivesinstructions from Function Bus Interface (FBI) 216 over function bus212. HE 220 executes the function calls in the order in which itreceives them on the function bus, for example by employing orderqueues. HE 220 might include order logic to store function calls for upto 64 contexts. Hash tables implemented by HE 220 are stored in systemmemory 112, via memory interface 224. Embodiments of HE 220 mightimplement up to 1024 independent hash tables. Each hash table might beallocated dedicated static memory at system startup of network processor100, but might also be dynamically allocated additional memory over timeas network processor 100 operates. In some embodiments, additionalmemory is allocated dynamically to a hash table in 256B blocks.

State Engine (SENG) 218 might perform functions of a finite statemachine (FSM) that operates on received packets. For example, SENG 218might perform statistics counts and run traffic shaper scripts. SENG 218might store statistics data in system memory 112, via memory interface224, and might employ a data cache to reduce accesses to system memory112 when there are multiple accesses to the same location of systemmemory.

MPP 200 might generally be implemented as a multi-threaded enginecapable of executing parallel functions. The multi-threading operationis performed by multiple contexts in MTIE 214. Some embodiments of MPP200 might employ more than one MTIE 214 to support additional contextprocessing. For example, MPP 200 might preferably include 4 MTIE cores,each capable of processing 32 contexts, for a total of 128 contexts.These contexts might be supported by 256 task identifiers (TIDs),meaning that contexts for up to 256 tasks might be concurrently activein MPP 200.

MPP 200 might typically receive input tasks via a task ring such asdescribed in U.S. patent application Ser. No. 12/782,379 filed May 18,2010. Additionally, MPP 200 might receive a timer event via a timerring. Receiving a task or receiving a timer event results in a contextbeing generated in MPP 200 corresponding to the received task or timerevent. Upon receiving a task, MPP 200 reads the task from system memory112, for example via communication interface 202 and memory interface224. Communication interface 202 issues a task start request to MTIEcore 214 via scheduler (SCH) 204. A typical task might include 32 bytesof parameter data, and a typical timer event might include 13 bytes ofparameter data.

SCH 204 tracks MPP contexts and maintains a list of free contexts. Uponreceiving a task start request, if a free context is available, SCH 204issues a context start indication to one or more other modules of MPP200 such that the various modules, if necessary, might initializethemselves to process the context. SCH 204 also maintains task templateto root address table 228. Root address table 228 specifies theinstruction entry point (e.g., the address of first instruction in flowmemory 230) for a given task template. Root address table 228 mighttypically be loaded on initial configuration of MPP 200.

Upon receiving the context start indication from SCH 204, MTIE 214initializes its internal context memory and loads the task parameters ofthe received task. MTIE 214 also loads the root address to use for thecontext from root address table 228, such that MTIE 214 can determinewhat processing to perform for the received input task. Upon receivingthe context start indication from SCH 204, Data Buffer Controller 206initiates a data read operation to read the packet data corresponding tothe context from at least one of system memory 112 and external memory116. HE 220, FBI 216 and PIC 210 reset various valid bits for errordetection for the context.

After the context start indication is issued, SCH 204 issues a contextschedule indication to MTIE 214. In response to the context scheduleindication, MTIE 214 starts executing a first command stored at thelocation specified in root address table 228. The command might bestored in at least one of root tree memory 232, flow memory 230, andexternal tree memory 234. While executing the specified commands, MTIE214 fetches tree instructions from either root tree memory 232 orexternal tree memory 234. MTIE 214 also fetches flow instructions fromflow memory 230. Some embodiments might include a 16 KB flow memory foreach MTIE core of MPP 200, and some embodiments might further allow theflow memory for multiple MTIE cores to be shared to increase the size ofthe flow memory for all MTIE cores.

Upon reaching a point in context processing that requires processing bya module of MPP 200 external to MTIE 214, MTIE 214 sends the contextalong with the corresponding function call and arguments to FBI 216.Once the context is delivered to FBI 216, the context might becomeinactive in MTIE 214 as, in general, a given context might only beactive in one module of MPP 200 at any one time. FBI 216 provides thefunction call to the designated unit for execution via function bus 212.Although function bus 212 is shown in FIG. 2 as a single bus, someembodiments might employ more than one function bus 212, based on thetype of module that is coupled to each bus. In general, function bus 212might be employed to communicate between MTIE 214 and HE 220, PIC 210,SEM 222, PQM 208 and SENG 218.

Data Buffer Controller (DBC) 206 might implement the data bufferfunction. DBC 206 fetches PDU data for MTIE 214 from memory external toMPP 200 (e.g., one of system memory 112 or external memory 116). DBC 206might issue a read indication signal and a read done indication signalto FBI 216 to schedule the read requests. DBC 206 might have up to 2read requests pending at any time for a given context. FBI 216 mightprevent context termination if DBC 206 has pending reads for thecontext.

For functions that are defined as ordered, FBI 216 sends out functioncalls in the order in which the contexts are started in MPP 200. Forfunctions that are not defined as ordered, FBI 216 might send outfunction calls in the order they are received by FBI 216. FBI 216 mighttypically queue contexts so that generally newer contexts wait for thegenerally oldest context to be executed. FBI 216 also determines therouting of each function call to a destination module and determineswhether the function returns any data upon completion. If a functioncall does not return data, then FBI 216 sends the context to SCH 204when the destination module returns an indication that it has startedprocessing the function call. If the function call does return data,then FBI 216 sends the context to SCH 204 after the data is returned toFBI 216 by the destination module. Upon receiving the data, FBI 216sends the data to MTIE 214, and MTIE 214 writes the data to an internalmemory (not shown). Once the returned data is written to memory, thecontext is provided to SCH 204. Additionally, FBI 216 might determine ifa function call is a “terminating” function call that ends contextprocessing by MPP 200. Terminating function calls might typically beissued by Pre-Queue Modifier 208 directly to SCH 204. When a terminatingfunction call is processed, MPP 200 generates an output task that iscommunicated, for example, over a ring communication bus to a nextmodule of network processor 100 for subsequent processing after MPP 200.

MPP 200 might track a virtual flow identifier (vflow ID) and an index(vflow Index) with each output task, indicative of what one(s) of cores106 or accelerators 108 operate on a data packet after MPP 200 hasfinished its processing. Communication interface 202 generates an outputtask based on the vflow ID and vflow Index and the output task istransmitted, for example via a task ring, to the subsequent destinationmodule. An input task might result in the generation of multiple outputtasks. As described herein, MPP 200 maintains task order between inputand output, such that output tasks are generated in the order in whichthe input tasks are received by MPP 200, and thus also the order inwhich the corresponding contexts are started in MPP 200.

SCH 204 starts a new context when new tasks are received by MPP 200. SCH204 receives a Task ID (TID) that identifies the received task andstarts a context by allocating a context number to associate with thattask. The TID and context number might be passed on to other modules ofMPP 200 when the context is started. A context is associated with thisTID and context number until SCH 204 receives an indication thatprocessing of the context is terminated. In general, a new context isstarted for a received task if the following conditions are true: (1)there are available contexts; and (2) a Task Start FIFO buffer hasenough available entries for at least one complete task. To start a newcontext, SCH 204 reads task information from one or more Task Start FIFObuffer locations. The Task Start FIFO buffers might be FIFO buffersstored in an internal memory of SCH 204. SCH 204 starts a context byallocating a new context number and setting a status bit of the context,indicating that this context is ready to be scheduled. SCH 204 storesthe task information in a Per-Context Memory (PCM) of SCH 204. The PCMmight be addressed by context number. In some embodiments, the PCM isimplemented as a two-port memory with one port dedicated to writecontext information, and one port dedicated to read context information.The context information might also be provided to other modules of MPP200 when the context is started, allowing the modules to initialize anyper-context memories for the new context.

As will be described, SCH 204 maintains a Classification Completion List(CCL). The CCL stores pointers to the contexts and control data, such ascontext start order, context number, and thread identifiers (THID), foreach context. When a new terminating function is issued by PQM 208 toSCH 204, the terminating function is appended to the CCL after any olderCCL entries for the corresponding context. The next newest context, forexample the next context in the CCL linked list, is then started. When acontext becomes the oldest context in MPP 200, SCH 204 reads the CCLcontents and sends them to PQM 208 to form instructions to communicationinterface 202 to generate a corresponding output task that is, forexample, based on a vflow ID, a vflow Index, and the actual packet data.SCH 204 might determine which context is the oldest if the context isthe head entry of the CCL linked list. Alternatively, if SCH 204 employsmore than one output queue, a CCL linked list might exist for eachoutput queue, and, thus, SCH 204 might select the oldest context fromone of the output queues, and sends that context to PQM 208. Since anordering requirement between OQs is not necessary, any non-empty OQmight be selected (for example, using a round robin algorithm) to begintransmission.

The CCL location is freed for another context and the output task issent to the next destination module of network processor 100. When acontext is terminated, that context is not reallocated until all othermodules of MPP 200 have acknowledged to SCH 204 that they are doneprocessing the context. Thus, as described herein, SCH 204 providescontext start and context complete information to other modules of MPP200, and provides context scheduling information to MTIE 214. As will bedescribed, MTIE 214 might also provide instruction breakpointinformation to SCH 204.

In situations where one or more system resources are running low, SCH204 might stop scheduling contexts that consume the resources. Thus, SCH204 might place a context in a “parked mode”. While a context is parked,SCH 204 will not schedule it to MTIE 214. SCH 204 might place a contextin parked mode for any of the following cases. For case (1), the contextis placed in a parked mode when free locations in the ClassificationCompletion List (CCL) are below a minimum threshold, thus becoming atrisk of not being able to satisfy all active contexts. In thiscondition, any context that allocates a new CCL location, and is not aterminating function, is parked by SCH 204. A context parked for thisreason remains parked until free locations in the CCL are above theminimum threshold. For case (2), the context is placed in a parked modewhen PQM 208 instruction memory is below a minimum threshold and at riskof not being able to satisfy all the active contexts. In this condition,any context that uses PQM instruction memory is parked by SCH 204. Acontext parked for this reason remains parked until free PQM instructionmemory is above the minimum threshold. In some embodiments, contextsparked for either cases (1) or (2) might remain parked until the testsfor both cases (1) and (2) are satisfied, for example, that freelocations in the CCL are above the minimum threshold and free PQMinstruction memory is above the minimum threshold. For case (3), thecontext is placed in a parked mode when SCH 204 parks a context due toan instruction breakpoint, which might be performed for diagnosticpurposes. Thus, a context might be parked due to system resources beingbelow a minimum (e.g., one or both of free locations in the CCL and freePQM instruction memory) or a context might be parked because of aninstruction breakpoint.

The instruction breakpoint mechanism allows stepping through softwarecode using a configuration-specified instruction breakpoint. As will bedescribed, when a MTIE 214 executes an instruction that has a breakpointset, and a breakpoint mode is enabled, MTIE 214 signals SCH 204 to parkthe context. Multiple contexts might be parked in this manner in asingle clock cycle, since each of the one or more MTIE modules has anindependent interface to SCH 204. Upon reaching an instruction having abreakpoint, MTIE 214 might send the context to SCH 204 with acorresponding breakpoint indication set. Upon receiving a context withthe breakpoint indication set, SCH 204 might request all of the one ormore MTIE modules to send all the active contexts to SCH 204 and put thecontexts in instruction breakpoint park mode. Once SCH 204 has receivedcontrol over all active contexts, SCH 204 might generate an interrupt,for example, to one of the various μP cores 106 of network processor100.

Through debug interface 236, a module external to MPP 200, for examplethe one of μP cores 106 that received the interrupt, might interrogatethe state of MTIE 214, SCH 204, and other modules of MPP 200. After theone of μP cores 106 that received the interrupt is finishedinterrogating the state of MPP 200, the interrupt might be cleared toreturn MPP 200 to a running state, for example by clearing the schedulercontrol register. When returned to a running state, SCH 204 clears theinstruction breakpoint park for all contexts, allowing them to berescheduled to MTIE 214. When not in breakpoint mode, for each clockcycle, SCH 204 attempts to pick a context to schedule to MTIE 214, basedon the status of the contexts, for example, contexts with a “ready”status and that are not parked. When SCH 204 is in breakpoint mode, nocontexts are rescheduled, and no new contexts are started.

MTIE 214 includes flow memory 230. Flow memory 230 might be 24 bits wideand 16 KB in size. The first (e.g., lowest addressed) flow instructionsmight be stored in the flow instruction cache of flow memory 230, whilesubsequent instructions (e.g., higher addressed flow instructions) mightbe mapped by a base register of MTIE 214 and stored in external treememory 234. In exemplary embodiments, MPP 200 might include 1, 2, 4, 6or 8 MTIE cores. In embodiments with multiple MTIE cores, the flowmemory of one or more cores might be joined together to increase theflow memory size for the overall group of MTIE cores. In general, flowmemory 230 might have a lower read latency versus external tree memory234.

MTIE 214 includes root tree memory 232. Root tree memory 232 mightinclude 1K of memory and might contain the first 1024 tree instructionsfor zero latency instruction access. In general, root tree memory 232might have a lower read latency versus external tree memory 234. Toimprove the read latency of external tree memory 234, data might beduplicated across one or more locations of external tree memory 234. Forexample, as will be described, one logical address might be mapped toone or more physical addresses in external tree memory 234. The contentsof the tree memory might be duplicated across one or more physicalmemory banks of external tree memory 234 to reduce memory contention forfrequently accessed instructions.

Described embodiments reduce the average latency of read requests to amemory that is read by one or more requestors, where the memory mightinclude two or more substructures (e.g., multiple banks of DRAM). Insuch a system, a latency penalty might be incurred for read requests tothe same substructure sequentially, and the average latency of readrequests might be reduced by having multiple copies of the same data inmultiple memory substructures. In such an embodiment, a requestor mightinitiate a read request to the substructure that holds a copy of thedata that will incur the smallest latency. This decision might be basedon knowledge of prior requests and which data is duplicated. Indescribed embodiments, the address of the read request is used to lookupthe availability of duplicated data from a programmable table based onaddress ranges.

Embodiments of the present invention further provide that the data to beduplicated can be chosen as less than all the data, based on usagestatistics of the data and the size of available memory. For example,heavily used data might be duplicated in all of the memory substructuresto minimize access time, while infrequently used data would have fewercopies or not be duplicated at all, allowing more overall data to bestored in the memory. Thus, the level of data duplication isconfigurable based on the requirements of a given implementation ofnetwork processor 100.

FIG. 3 shows a block diagram of exemplary tree memory 234. As shown,external tree memory 234 includes having M substructures, 316(1)-316(M),where M is a positive integer. MTIE 214 might include lookup table 304,which has N entries, where N is a positive integer, each correspondingto a number of different data regions with different types ofduplication that could be defined for the overall memory structure. Forexample, additional table entries allow additional substructures to besupported. The number of bits used for the address, address ranges andtable comparisons might define a minimum granularity of each addressrange per memory substructure. Each of the N table entries includes avalid indication (Valid), an address range (IBASE and IEND), and a dataduplication structure base address (SBASE) and a data duplication factor(DF).

When MTIE 214 requires data from one of root tree memory 232 andexternal tree memory 234, MTIE 214 sends a read request external treememory 234. Read requests might be temporarily stored in tree memoryFIFO 302. Comparator 306 compares at least a portion of the requestedaddress against the entries of lookup table 304. Comparator 306 returnsthe value Table_Hit, which is a match indication for the table indexwhose address range included the request address. For example, when therequested address is less than or equal to the ending address of theaddress range (IEND[N]) and is greater than or equal to the base addressof the address range (IBASE[N]), and when the corresponding validindication (Valid[N]) is set. For example, in described embodiments,MTIE 214 might perform the address range comparison:Table_Hit[N−1:0]=(Valid[N] && (IBASE[N]<=Request Address<=IEND[N])). Theinformation about how the data in that address range is duplicated(DF[N]) and any other information (SBASE[N]) required to transform therequest address into an actual structure address is read by SubStructureSelector and Address Former 314 from the matching entry of lookup table304 defined by the Table_Hit value, and selected by multiplexer 310.

MTIE 214 might also maintain a corresponding “busy” indicator for eachmemory substructure, for example, SubStructure Status BitMask 312, whichincludes a bitmask of SubStructure_(—Busy[M−)1:0]. Based on therequested address, address translation information is read from thetable and, based on the address translation information and the “busy”state of the memory substructure that includes the requested address,SubStructure Selector and Address Former 314 might determine a memoryaddress to read that would result in the minimum latency. SubStructureStatus BitMask 312 is updated for the substructure that receives therequest, allowing its ability to accept future requests to be tracked.

FIGS. 4-6 show additional exemplary conditions for accessing root treememory 232 and external tree memory 234. Although FIGS. 4-6 show theexemplary case where external tree memory 234 employs two memory banks,other numbers of memory banks are possible. An exemplary embodiment ofthe present invention might desirably employ 8 memory banks, where someor all data could be duplicated in 0, 2, 4 or all 8 memory banks. When asingle requestor accesses a tree memory with 2 memory banks of 8addresses per bank, part of the structure address might indicate thememory bank, part of the structure address might indicate the addresswithin the bank. Typically, there might be a one clock cycle latencypenalty for accessing a bank that was accessed the prior clock cycle. Inthe exemplary case of two memory banks, if the base address of the treememory is 0, such that the valid structure addresses for the memory are0-15, even addresses might be located in bank 0 and odd addresses inbank 1, such as shown in FIGS. 4-6. A table duplication factor of 0indicates no duplication for the data and a duplication factor of 1indicates the data is duplicated in both banks.

SubStructure Status BitMask 312 might include one bit per memory bank.SubStructure Status BitMask 312 might set an indicator, such as a flagbit, for one cycle after a bank was accessed to indicate that thecorresponding memory bank is busy for one clock cycle to process a readrequest. The indicator for the corresponding memory bank might clear thefollowing clock cycle to indicate that the memory bank is available toaccept new read requests. For substructures that have more than a oneclock cycle latency penalty between requests, their status could betracked with a counter, shift register or some similar mechanism toindicate their busy status over multiple clock cycles. For dynamicsubstructures that require periodic refresh cycles, the refresh statusof the structures might also be tracked and used as input to at leastone of SubStructure Selector and Address Former 314 or SubStructureStatus BitMask 312.

FIG. 4 shows an exemplary case where data is not duplicated in one ormore substructures of external tree memory 234. In the exemplary case ofFIG. 4, external tree memory 234 has 2 memory banks, each with 8 memoryaddresses, as described above. Also as described above, some embodimentsof the present invention might employ additional memory banks, and eachmemory bank might include more than 8 memory addresses. Valid values ofthe request address of MTIE 214 would be all possible addresses, 0-15 (4bits for 16 unique addresses). As shown, in this case lookup table 304would have just one entry with IBASE and IEND set to include the entireaddress range (IBASE=0 and IEND=15). The DF value is set to 0 indicatingno duplication. The SBASE value is 0, indicating memory bank 0, and thestorage address generated by SubStructure Selector and Address Former314 is the same as the request address. If there are back-to-back readrequests to the same memory bank, the second read request is stalled fora clock cycle until the first read request is issued, as described abovewith regard to SubStructure Status BitMask 312. For example, if thefirst request is to bank 0, SubStructure_Busy[0] is set to indicate bank0's busy status. Upon receiving the second request, SubStructureSelector and Address Former 314 sees SubStructure_Busy[0] is set andwaits another clock cycle before issuing the read request. Requestaddresses 0-15 map to structure addresses 0-15, as shown.

FIG. 5 shows the exemplary case where data is duplicated completelybetween both banks. Valid values of the request address are limited tothe values 0-7 (8 unique items) instead of 0-15 (16 unique items).Lookup table 304 has one entry with IBASE and IEND set to include thelimited address range (IBASE=0 and IEND=7). The DF value is set to 1indicating that all data exists in both banks. The SBASE value is 0,indicating memory bank 0, and the storage address generated bySubStructure Selector and Address Former 314 is formed by concatenationof the lower 3 bits of the request address and the bit that indicatesthe selected bank.

If there are back-to-back read requests, SubStructure Selector andAddress Former 314 might provide the first read request to either memorybank. SubStructure Selector and Address Former 314 might provide thesecond read request to the bank that was not selected for the first readrequest. For example, if the first request went to bank 0, it would setSubStructure_Busy[0] to indicate bank 0's busy status. For the secondrequest in the next clock cycle, SubStructure Selector and AddressFormer 314 reads SubStructure_Busy[0] indicating that bank 0 is busy,sends the second request to bank 1, and sets SubStructure_Busy[1] toindicate bank 1's busy status. For a third request in the next clockcycle, SubStructure_Busy[0] indicates that bank 0 is available, andSubStructure_Busy[1] indicates that bank 1 is busy, and the third readrequest is sent to bank 0, and so on, for subsequent read requests.Request addresses 0-7 map to structure addresses 0-7 and 8-15.

FIG. 6 shows the exemplary case where the first 8 data items are notduplicated, but the next 4 data items are duplicated across both memorybanks. Valid values of the request address are limited to the values0-11 instead of 0-15 (12 unique items). As shown, lookup table 304 hastwo entries with the following information:

-   -   Table[0]: IBASE=0, IEND=7, SBASE=0, DF=0 (locations 0-7 not        duplicated), and    -   Table[1]: IBASE=8, IEND=11, SBASE=4, DF=1 (locations 8-11        duplicated).        For data addresses that are not duplicated (e.g., DF=0), the        storage address is the request address (e.g., 0-7). For data        addresses that are duplicated, the storage address might be        formed by SubStructure Selector and Address Former 314 by        concatenating the request address with one or more values from        lookup table 304. SubStructure Selector and Address Former 314        might form the storage address by performing the concatenation:        (Requested Logical Address−IBASE+SBASE) and, if data duplication        is enabled (e.g., DF=1), and shifting the result by a number        corresponding to the number of memory banks with the data        duplication. As shown in FIG. 6, request addresses 0-7 map to        structure addresses 0-7, and request addresses 8-11 map to        structure addresses 8 and 9, 10 and 11, 12 and 13, and 14 and        15, respectively.

For example, in the exemplary case shown in FIG. 6 where some data isduplicated across two memory banks, a requestor might attempt to accessthe data stored in logical address 9, which is duplicated in physicaladdress 10 in memory bank 0, and physical address 11 in memory bank 1.As shown, to access logical address 9, IBASE is equal to 8 and SBASE isequal to 4. Thus, the calculation (Requested LogicalAddress−IBASE+SBASE) results in: 9−8+4=5. This resulting value is thenleft shifted by a number of bits corresponding to the number of memorybanks with data duplication, since DF=1. In the exemplary case shown inFIG. 6, two memory banks are employed. Thus, the resulting value is leftshifted by one bit, which, depending on the value of the new leastsignificant bit, results in the value 5 (101) being left shifted by onebit (101 x), which could be either address 10 (1010) or address 11(1011). If more than 2 memory banks are employed, the result might beshifted correspondingly by additional bit places. The value of the newleast significant bit might be selected by SubStructure Selector andAddress Former 314 based on, for example, the SubStructure_Busy statusvalues of memory bank 0 and memory bank 1. Thus, logical address 9corresponds to physical addresses 10 and 11, and one of the physicaladdresses is chosen based on the availability of the correspondingmemory banks.

Alternatively, in the exemplary case shown in FIG. 6 where some data isduplicated across two memory banks, a requestor might attempt to accessthe data stored in logical address 6, which is not duplicated. As shown,to access logical address 6, IBASE is equal to 0 and SBASE is equal to0. Thus, the calculation (Requested Logical Address−IBASE+SBASE) resultsin: 6−0+0=6. This resulting value is not left shifted by a number ofbits corresponding to the number of memory banks with data duplication,since DF=0. Thus, the physical address and the logical address areequal. Although shown in FIGS. 4-6 as having two banks, the presentinvention is not so limited, and additional memory banks might beemployed.

Table 2 defines terms used herein as an aid to understanding thedescribed embodiment:

TABLE 2 Packet processing system a system that receives packets from oneor (“PPS”) more sources, performs some function(s) on those packets, andsends packets out to one or more destinations Thread the product of aPPS receiving one or more input packets and combining them into a newpacket, which might then be output from the PPS. Scheduler (“SCH”) acomponent in a PPS that receives information from one or more inputpackets comprising one or more threads, and is responsible forscheduling the transmission of completed threads. Thread Start (“TS”)notification received by SCH for the first input packet for a particularthread. The SCH defines a maximum number of threads it maysimultaneously have in progress, and prevents any new threads from beingstarted if this limit is reached. Classification Completion alinked-list structure used by the SCH to List (“CCL”) store informationneeded for the transmission of a portion of a thread (e.g., from aparticular input packet). A sequence of one or more entries in the CCL(one per input packet) contains information for the SCH to transmit theentire thread. The CCL stores this information in the order in which theinput packets are received by the SCH, but is read in the wire order, asdescribed herein. Output Queue (“OQ”) a structure used by the SCH tospecify the transmission order for a subset of threads managed by theSCH. The SCH may support multiple Output Queues. Each thread specifiesits Output Queue to use, sometime after the thread is started, andbefore or coincident with the first input packet for the thread. ThreadID (“THID”) a unique identifier used to refer to a particular threadthat is in progress. Per-Thread Table (“PTT”) a table used by the SCHtable (addressed by THID) to record information about a particularthread, including its location in the CCL. Oldest Unspecified List alist used by the SCH to track the order in (“OUL”) which the TS werereceived for each thread in progress. The oldest thread in the list isremoved after it has specified its OQ. Queue Table (“QT”) a table usedby the SCH to track the OQ specified for each THID. Reassembly theproduct of a PPS receiving one or more input packets and combining theminto a new packet, which may then be output from the PPS PacketAccumulation PPS component that creates reassemblies Component (“PAC”)from input packets and optionally sends them to an output Per-reassemblyState state (information, data) that a PAC maintains for eachreassembly. The PAC uses this state when processing input packets, eachof which refers to a particular reassembly. The PAC stores this state insystem memory 112. Enqueue Packet An input packet to be added to theindicated reassembly Transmit Packet An input packet to be transmittedin an output packet

MPP 200 might typically employ multi-threaded processing to interfacewith high latency memory systems. As input packets arrive, MPP 200starts a thread by sending a Thread Start (TS) indication to SCH 204. Anew thread might start execution even when an older thread has notcompleted execution. A newer thread might complete execution before anolder thread has completed execution. SCH 204 might include multipleoutput queues (OQ), and each thread might specify its corresponding OQbefore starting output transmission. SCH 204 maintains “wire order” on aparticular OQ, meaning that each OQ transmits the packets for a giventhread contiguously in the order in which the threads were started,regardless of any interleaving of the input packets between threads.Embodiments of the present invention allow efficient implementation ofwire order transmission in a multi threaded, multi OQ system. Describedembodiments provide SCH 204 to efficiently transmit threads in the orderin which they were started, and to select them from multiple OQs.

As described herein, MPP 200 transmits packets in wire order. Tables 3-5show an exemplary condition for processing packets of 3 threads in asystem employing two output queues (OQ0 and OQ1). As shown in Tables3-5, below, an ordering requirement is not necessarily required betweenOQ0 and OQ1. In these tables, the OQ is shown as being specified in theTS indication, but the OQ corresponding to a thread might be specifiedat any time up until or coincident with MPP 200 receiving the firstpacket for a given thread.

TABLE 3 Input Packet Arrival Order into Scheduler 204 Thread 0: Start,OQ 0 First to Arrive Thread 1: Start, OQ 0 Thread 2: Start, OQ 0 Thread3: Start, OQ 1 Thread 2: Packet 0 Thread 1: Packet 0 Thread 3: Packet 0Thread 1: Packet 1 Thread 2: Packet 1 Thread 0: Packet 0 Thread 3:Packet 1 Thread 2: Packet 2 Thread 2: Packet 3 Thread 1: Packet 2 Thread0: Packet 1 Last to Arrive

TABLE 4 Required Output Packet Order from Scheduler 204 OQ 0 Thread 0:Packet 0, 1 First output from OQ0 Thread 1: Packet 0, 1, 2 Thread 2:Packet 0, 1, 2, 3 Last output from OQ0

TABLE 5 Required Output Packet Order from Scheduler 204 OQ 1 Thread 3:Packet 0, 1 First/Last output from OQ1

Tables 3-5 show an exemplary case of a last overall packet received forvarious active threads. When the last packet for a particular thread istransmitted, it is an indication for the next thread in that particularOQ (if any) to begin transmission.

One embodiment of MPP 200 might transmit the thread for the first inputpacket to arrive, and continue transmitting each input packet as itarrives, enqueuing all other input packets (those for other threads)into a relatively large queue. After the last input packet is receivedfor the given thread, SCH 204 begins processing the next oldest entry inthe queue (deleting it from the head of the queue), and traverses thequeue from oldest to newest, extracting (and transmitting) any entriesthat pertain to the next thread. If any input packets were received forthat thread while SCH 204 was traversing the queue, SCH 204 enqueuesthat input packet into the large queue. If SCH 204 reached an entrywhich was the last entry for that thread, SCH 204 would then begintransmitting a new thread starting with the (next) oldest queue entry,starting back at the head of the queue. SCH 204 continues this algorithmunless or until the queue was empty. If SCH 204 traversed the entirequeue without finding the last entry for the thread, SCH 204 stopstransmitting until the last input packet for that thread was received.This embodiment might be relatively inefficient since the entire queuewould need to be repeatedly traversed; if there were a large number ofthreads in progress, this could take a very long time. This embodimentrequires a large amount of memory for SCH 204 to support a large numberof simultaneously-active threads.

FIG. 7 illustrates how thread information flows from input packets tooutput packets through OUL 702 and OQs 704(1)-704(N). The OQs are linkedlists whose links are stored in CCL 802. FIG. 8 shows ClassificationCompletion List (CCL) 802 and other pointer structures, includingorganization of the OQ and per-THID link information. The information inQueue Table (QT) 806 and Per-Thread Table (PTT) is employed by SCH 204to update the links within CCL 802 in order to maintain each thread'slinked list and each OQ's linked list.

As shown in FIG. 8, another embodiment of MPP 200 might include CCL 802,which is a linked-list structure used by SCH 204 to store informationfor the transmission of a portion of a thread (e.g., from a particularinput packet). A sequence of one or more entries in CCL 802 (one entryper input packet) contains information for SCH 204 to transmit theentire thread. CCL 802 stores the information in the order in which theinput packets are received by SCH 204. However, CCL 802 is read in thewire order.

As described, CCL 802 is a linked list which stores informationnecessary to transmit a particular input packet associated with aparticular thread. Each CCL entry includes a link pointer to another CCLentry (either the next CCL entry for that thread, or the first entry ofthe next thread in the same OQ). Each CCL entry also stores the threadidentifier (THID) of the thread and an indication if the entry is thelast CCL entry for the thread (not necessarily the last in the OQ). Theentries for a given thread stored in CCL 802 are linked to each other.Threads that have specified their OQ have their smaller linked listswithin CCL 802 linked together.

SCH 204 maintains a Head Pointer (shown as 804(1)-804(N)) and a TailPointer (shown as 805(1)-805(N)) in Per-Thread Table (PTT) 808 for eachOQ 704(1)-704(N). The HP points to the oldest CCL entry for a given OQ.The oldest CCL entry is the next entry to be transmitted for that queue.The TP points to the newest (last) CCL entry for the given OQ.

Oldest Unspecified List (OUL) 702 is a list used by SCH 204 to track theorder in which the TS indications were received for each thread. Theoldest thread in the list is removed after it has specified its OQ. OUL702 is an ordered list of THIDs for which SCH 204 has received a TS. Theoldest entry is not read from OUL 702 until it has specified its OQ.

Queue Table (QT) 806 is a table used by SCH 204 to track the OQspecified for each THID. QT 806 is a per-THID table that records the OQnumber specified for a given THID, and a valid bit indicating whether ornot that THID has yet specified its OQ number. PTT 808 records, for eachTHID, the head pointer (oldest) and tail pointer (newest) entry for thatthread within CCL 802. At a given point in time, these smaller linkedlists may or may not be linked to other linked lists within CCL 802,depending on whether or not the thread has been moved out of the OUL.

When SCH 204 receives an indication of the start of a thread, SCH 204records the TS indicator in OUL 702. Entries in OUL 702 are written inthe order in which the threads are started, and read in the same order.Before, or coincident with when SCH 204 receives the first input packetfor a thread, SCH 204 receives an indication of which OQ the thread isto use. SCH 204 records this OQ number in QT 806 and sets the valid bitfor that QT entry. When SCH 204 receives an input packet for a thread,it updates PTT 808. A new CCL entry is allocated for the input packet,and the corresponding HP and TP of PTT 808 for that THID are updated tolink in the new CCL location. If this is the first packet for thethread, PTT 808 HP and TP are both set to point to the new CCL entry. Ifthere are already one or more CCL entries for the thread, the oldest CCLentry link is pointed to the new CCL entry, and PTT 808 TP is set topoint to the new CCL entry. The information necessary to transmit thepacket is also written to CCL 802, as well as the indication of whetheror not the packet is the last one for this thread.

While a thread is in OUL 702, OUL 702 might receive input packets. Ifthe thread is not the oldest OUL entry, and the oldest entry has not yetspecified its OQ (that is, the valid bit in the QT is still 0), thethread must remain in OUL 702. The corresponding entry of PTT 808 forthe thread is updated, but the thread is not yet “moved” out of OUL 702(e.g., not linked to an OQ). When the oldest thread in OUL 702 hasspecified its OQ, the thread is moved into CCL 802 in the specified oneof OQs 704(1)-704(N).

As shown in FIG. 9, if the thread from OUL 702 already has one or moreinput packets, and the OQ currently linked into is not empty, then theentry of CCL 802 that is pointed to by the current OQ TP is linked tothe HP of the thread (recorded in PTT 808), and the OQ TP is set to theTP of the thread (from PTT 808). As shown in FIG. 10, if the thread fromOUL 702 already has one or more input packets, and the OQ being linkedinto is empty, then the HP and TP for the OQ are set to the HP and TPfor the thread as stored in PTT 808. As shown in FIG. 11, if the threadfrom OUL 702 does not have any input packets, and the OQ being linkedinto is not empty, then a CCL entry is allocated and written with anindication that the entry has not yet been “used” by an input packet.The CCL entry pointed to by the current OQ TP is linked to the new CCLentry, and the OQ TP is set to point to the new CCL entry. As shown inFIG. 12, if the thread from OUL 702 does not have any input packets, andthe OQ being linked into is empty, then a CCL entry is allocated andwritten with an indication that the entry has not yet been “used” by aninput packet, and the HP and TP for the queue are set to the new CCLentry.

FIGS. 9-11 and Tables 6-9 show the effect on the pointers and CCL whenmoving an entry from OUL 702 to one of OQs 704(1)-704(N), in each of thefour scenarios described above. As described, FIG. 9 shows Moving aNon-empty Thread to a Non-Empty OQ, FIG. 10 shows Moving a Non-emptyThread to an Empty OQ, FIG. 11 shows Moving an Empty Thread to aNon-Empty OQ, and FIG. 12 shows Moving an Empty Thread to an Empty OQ.After the sequence of input listed in Table 3, SCH 204 structuressupporting this invention would appear as shown below in Tables 6-9.Table 6 shows the contents of OUL 702 before any threads have been movedout of it. Table 7 shows the contents of QT 806, Table 8 shows CCL 802after the threads have been moved into the CCL, and Table 9 shows thecontents of PTT 808.

TABLE 6 contents of OUL 702 THID 3 Newest THID 2 THID 1 THID 0 Oldest

TABLE 7 contents of QT 806 THID Queue Number Valid 0 0 1 1 0 1 2 0 1 3 11 000 X X n X 0

TABLE 8 contents of CCL 802 CCL Link (next Last in Head/Tail locationContents CCL location) Thread Pointers Last 10 THID 0, Packet 1 1 1location written 9 THID 1, Packet 2 0 1 8 THID 2, Packet 3 X 1 OQ0 TP 7THID 2, Packet 2 8 0 6 THID 3, Packet 1 X 1 OQ1 TP 5 THID 0, Packet 010  0 OQ0 HP 4 THID 2, Packet 1 7 0 3 THID 1, Packet 1 9 0 2 THID 3,Packet 0 6 0 OQ1 HP 1 THID 1, Packet 0 3 0 First 0 THID 2, Packet 0 4 0location written

TABLE 9 contents of PTT 808 THID HP (CCL Entry) TP (CCL Entry) 0 5 10 11 9 2 0 8 3 2 6

When there are any non-empty OQs, transmitting threads might bepermitted to start. Since an ordering requirement between OQs is notnecessary, any non-empty OQ might be selected (for example, using around robin algorithm) to begin transmission. Once an OQ is selected,the selected OQ is the only OQ to transmit until the end of the threadis reached, which can be determined by examining the “Last” bit storedin the CCL. To transmit a thread, SCH 204 selects a non-empty OQ andbegins reading locations from CCL 802 using the OQ HP for the selectedqueue. If SCH 204, when it selects an OQ to transmit, is in the middleof a current transmission, SCH 204 stays in this mode until it reads aCCL entry which has the Last bit set.

Before transmitting, SCH 204 examines the oldest entry in the OQ (theCCL entry pointed to by the OQ HP). If the next entry to be read has adifferent THID than the last entry read, and the previous entry did nothave the Last bit set, SCH 204 stops transmitting until the next (andpossibly last) packet for the thread is received. In this case SCH 204enters “Bypass Mode”, and records the THID of the thread which SCH 204is in the middle of transmitting. SCH 204 also enters “Bypass Mode” ifthe OQ becomes empty after reading a location which did not have theLast bit set. Otherwise, if SCH 204 reads and transmits an entry whichhas the Last bit set, then it is no longer in the middle of transmittinga thread and may select any non-empty OQ for the next thread totransmit.

While SCH 204 is in Bypass Mode, if it receives a new input packet itexamines the THID for the packet. If the THID matches the THID for whichit is in Bypass Mode (the bypass THID), then the packet information ispassed right to the output, bypassing the CCL. SCH 204 remains in thismode until such an input packet is received which has the Last bit set.If input packets are received which do not match the bypass THID, SCH204 handles the input packet in a normal manner by adding the inputpacket to OUL 702 and/or CCL 802. A particular THID is not necessarilyreused by MPP 200 until the THID has at least been moved from OUL 702 toCCL 802. At that time, the valid bit in the QT is reset to 0.

In the case where an empty thread is linked into an OQ, and a CCL entrymight be allocated but not yet used, the next (first) input packet forthat thread might use the CCL entry. One possible alternativeimplementation would be to not move the oldest OUL location into its OQuntil the first input packet is received for that thread; with thatalternative, there would never be the case of moving an empty thread toan OQ.

Embodiments of the present invention provide hardware instruction breakpoint capability in a multi-threaded processing environment. A dedicatedinstruction break point flag is added to each instruction word thatallows the execution engine to halt execution of the running thread andreturn it to the scheduler. The scheduler then signals the executionengine to return all remaining running threads to the scheduler andenter an idle state. Through a debug interface, the instruction breakpoint status of each thread in the scheduler can be queried and thethread state memories in the execution engine can be accessed foranalysis.

A typical software instruction break point might replace a giveninstruction with a special debugging instruction. Upon execution of thebreak point instruction, the running thread is halted. The debuginstruction is a part of the instruction set that the underlyingexecution engine decodes and executes similarly to any other instructionof the instruction set. Additionally, inter-thread communication mightbe required to bring the execution engine to an orderly idle statebefore debugging begins. Embodiments of the present invention provide ahardware instruction break point that adds a dedicated instruction breakpoint flag to each instruction word of the instruction set. If theinstruction break point is enabled and the instruction break point flagis set, the execution engine executes an implicit no op instruction andreturns the running thread to the scheduler. The scheduler then signalsthe execution engine to return all remaining running threads and enteran idle state. Multiple running threads might reach the same ordifferent instruction break points at the same time. Through a debuginterface, the instruction break point status of each thread might bequeried and the thread state memories in the execution engine might beread.

A dedicated instruction break point flag in the instruction word is usedto indicate to execution engine MTIE 214 that a running thread is to bereturned to SCH 204 to be parked due to the breakpoint. MTIE 214 mightinclude a configuration register to enable the instruction break pointflag. Upon receiving a thread including an instruction break point, SCH204 signals MTIE 214 to return all remaining running threads to SCH 204to be parked, thus putting MTIE 214 in an idle state.

As described herein, in a multi-threaded processing system such asnetwork processor 100, each thread executes a flow of instructions basedupon task assignment. Typically, an instruction set for such amulti-threaded processing system is small and each thread is allocatedstate memories such as instruction pointer, argument pointer, stack,global registers, and the like. As shown in FIG. 2, embodiments of thepresent invention provide that SCH 204 interfaces to execution engineMTIE 214.

FIG. 13 shows a flow diagram of instruction breakpoint operation 1300 ofSCH 204 and MTIE 214. At step 1302, a thread is first started by SCH204, and the thread's initial instruction pointer, flags, inputparameters and instruction break point mask are sent from SCH 204 toMTIE 214. MTIE 214 stores the thread inputs received from SCH 204 intoone or more thread state memories and at step 1304 retrieves the threadinstructions from an instruction memory, for example flow memory 230. Atstep 1306, if instruction breakpoint mode is disabled, the instructionbreakpoint flag in the instruction word is ignored and at step 1310,MTIE 214 executes the returned instruction word from instruction memory.At step 1306, if instruction breakpoint mode is enabled, MTIE 214executes an implicit no-op instruction at step 1308 instead of thereturned instruction word from the instruction memory. At step 1312, ifthe instruction breakpoint flag in the instruction word is set, at step1314 MTIE 214 saves the thread state and at step 1316 returns the threadto SCH 204 with an indication that an instruction breakpoint wasreached. At step 1318, upon receiving the returned thread from MTIE 214,SCH 204 parks the thread and signals MTIE 214 to return all remainingrunning threads. At step 1320, any threads returned by MTIE 214 areparked. Multiple running threads in the execution engine might hit thesame or different instruction break points concurrently.

SCH 204 waits at step 1322 for the breakpoint to be released, forexample, via a signal received from the debug interface. Through thedebug interface, the thread instruction breakpoint status in SCH 204might be accessed by devices external to network processor 100 via, forexample, a Joint Test Action Group (JTAG) interface, a Serial Wire Debug(SWD) interface, a Serial Peripheral Interface (SPI) or a UniversalAsynchronous Receiver/Transmitter (UART). Thread state memories in MTIE214 might similarly be accessed for analysis. Once the breakpoint isreleased by, for example, a device external to network processor 100 viathe debug interface, at step 1324 the parked threads are returned fromSCH 204 to MTIE 214 to resume instruction execution. At step 1324, whenSCH 204 returns parked threads to MTIE 214 to resume instructionexecution, SCH 204 also returns an indication of which instruction(s)first reached the breakpoint. At step 1310, MTIE 214 then executes theinstruction that first reached the breakpoint once it is returned fromSCH 204 without requiring the corresponding breakpoint flag to becleared first.

Processing of the thread might continue as described above until thethread is completed. At step 1326, if the thread is not complete, MTIE214 might retrieve the next thread instruction at step 1304. If thethread is complete, at step 1328, MTIE 214 returns the thread status toSCH 204. At step 1330, SCH 204 retires the competed thread and threadprocessing of the corresponding thread is complete. When multiplethreads are active, processing continues for each thread until eachthread is completed.

SCH 204 might include one bit vector per each context. Via the debuginterface, a breakpoint might be set on a particular address in theinstruction memory (e.g., flow memory 230) of MTIE 214. When thatparticular address is accessed by MTIE 214 to read and process thatinstruction, MTIE 214 recognizes the breakpoint and returns the threadto SCH 204, just as if the thread had completed normally. SCH 204 thenhalts all threads in MTIE 204 by requesting MTIE 214 return anyremaining threads to SCH 204. Thus, embodiments of the present inventionprovide a scheduler module to halt threads from one or more processor ofan SoC.

Embodiments of the present invention provide that threads in amultithreaded system might be allocated (started) in any order andde-allocated (terminated) in any order, and that processes associatedwith the threads are handled in the order in which the threads werestarted. Embodiments of the present invention define a per-thread statestructure, how the structure is managed when threads are allocated orde-allocated and how per-thread status information is used to find theoldest thread. This per-thread status structure allows for: i) trackingactive threads in thread start order; ii) single cycle update ofper-thread status on a thread de-allocate; and iii) single cycle lookupof the next oldest thread.

As described herein, network processor 100 might execute multiplethreads in parallel with functions for the various threads issuedwithout particular ordering. Synchronizing processing of these events orfunctions in the order the threads were started might be desirable.Specific events or functions that need to be ordered might be definedwithin submodules of network processor 100 such that only the threadsassociated with these functions are ordered. For example, functionsdestined for different modules might be defined to be ordered by FBI216. A list of active threads might be maintained in the order thethreads were started and this active thread list might be used forscheduling events or functions associated with the thread. Embodimentsof the present invention allow for management of active threads inthread start order and updates the active thread list on a threadde-allocate event. Further, embodiments of the present invention providesimplified lookup of the oldest active thread.

Some design implementations typically use linked list structuresmaintained in memory for tracking active threads. Removal of an activethread from middle of the linked list due to a thread de-allocate eventrequires 2 clock cycles: one clock cycle to read the link from memoryand a second clock cycle to write the value to different memorylocation. Since this operation takes two clock cycles, the operationrequires additional complexity, such as FIFOs and hold logic, forprocessing back-to-back thread de-allocate events. Another approachimplements event order lists or memory structures with a scalable numberof read ports, meaning that each read port has dedicated RAM for optimalperformance. The number of read ports is a function of how manyindependent events need to be synchronized, so, to prevent backup ofthreads in cases where oldest thread is not de-allocated for a longtime, the ordered list size might be large.

Embodiments of the present invention define i) a data structure fortracking currently active threads by thread start order, ii) allocateand de-allocate events to update the thread status information, and iii)a sequence value to identify next oldest thread in the list. As shown inFIG. 14, thread status data structure 1400 tracks up to N currentlyactive threads. Thread status data structure 1400 includes valid field1402(1)-1402(N) to indicate a valid active thread, sequence field1404(1)-1404(N) to track the sequence number of each thread, and thusthread start order, and thread field 1406(1)-1406(N) to identify whichthread corresponds to the respective entry of thread status datastructure 1400.

MPP 200 might maintain a global sequence counter that is incrementedeach time a new thread is allocated. When a thread is allocated, threadstatus data structure 1400 is updated such that the sequence field(e.g., the corresponding one of 1404(1)-1404(N)) for the thread isupdated with the sequence number. The valid bit (e.g., the correspondingone of 1402(1)-1402(N)) is set to 1. When the thread is de-allocated,the structure corresponding to the thread is updated. For any threadstructure with a sequence value greater or equal to the sequence valueof the de-allocated thread, the sequence value is decremented. The validbit is cleared for the de-allocated thread. The global sequence counteris decremented.

When a thread is de-allocated, the sequence value and thread valueassociated with this thread is read from thread status data structure1400. These values might be broadcast to modules of MPP 200, forexample, as shown in FIG. 15, one or more Event Scheduling Modules(ESMs) 1502(1)-1502(Y), to update their local current active sequencevalue. Each ESM with sequence value greater than the broadcast sequencedecrements its sequence value. In general, ESMs 1502(1)-1502(Y) might beany module of MPP 200 that schedules thread operations.

FIG. 15 shows a block diagram of Event Scheduler Modules (ESMs)1502(1)-1502(Y) interfacing to thread status data structure 1400. RdPort 1504 is provided for ESMs 1502(1)-1502(Y) to read thread statusdata structure 1400 to retrieve thread status data associated with thegiven sequence. Thread status data structure 1400 is maintained bythread state manager (TSM) 1500.

Thread status data structure 1400 might be updated by TSM 1500 throughcomparison logic (not shown) to determine if the incoming sequencematches the sequence associated with this thread. Structures with nomatches output a value of 0 for the thread. The sequence values for eachvalid thread are mutually exclusive; therefore, for any sequence, atmost there is generally only one match. All the output thread values arelogic ORed together by OR gate 1506 to generate a thread value. Rd port1504 is used by ESMs 1502(1)-1502(Y) to find the oldest thread in threadstatus data structure 1400. As described, the oldest thread is assignedsequence value of 0, until this thread is de-allocated, at which pointeach active thread has its corresponding sequence value decremented,where the thread with resulting sequence value of 0 is the oldestthread. As shown in FIG. 15, functions might be issued to an ESM in anyorder for a given thread. ESMs 1502(1)-1502(Y) then read thread statusdata structure 1400 to reorder the functions for issue in the threadstart order.

As shown in FIG. 15, ESMs 1502(1)-1502(Y) employ allocate interface 1508and de-allocate interface 1510 for maintaining their local sequencevalue and local thread status. The ESM thread status capturesinformation such as threads having events waiting to be scheduled andthreads that already have been scheduled. ESMs 1502(1)-1502(Y) use thethread value associated with incoming event to track threads waiting tobe scheduled. Initially, each ESM 1502(1)-1502(Y) has a sequence valueof 0 and if the thread associated with this sequence has a valid event,the event is scheduled. If there are more threads waiting to bescheduled for a given ESM, the sequence value is incremented by activethread counter 1516 and thread value associated with this sequence isrequested from thread status data structure 1400. This process continuesuntil all events have been scheduled, the thread associated with thesequence is not the oldest thread, or if the ESM has not yet received anevent for the thread value associated with this sequence. ESMs1502(1)-1502(Y) decrement their sequence values by thread decrementer1518 when the sequence value on de-allocate interface 1510 is less thanthe current sequence value. ESMs 1502(1)-1502(Y) might look up the nextoldest thread before the current oldest thread is de-allocated.

With more than one active thread in the system, each ESM might lookupthe next oldest thread information by advancing the local sequence valueand using it to request thread value via Rd Port 1506. Each ESM updatesits local sequence value appropriately when a thread de-allocate requestis provided on de-allocate interface 1510. ESMs 1502(1)-1502(Y) use thesequence value to adjust their local sequence values accordingly. ESMswith a local sequence value greater than or equal to the de-allocatesequence value decrement their local sequence values.

FIG. 16 shows a block diagram of an exemplary system timing where ESMO1602 and ESM1 1604 are ordering events having exemplary types func0 andfunc1. In the exemplary system there are 5 threads (0, 1, 2, 3, 4)started in incrementing order. As shown in FIG. 16, TSM 1500 receivesthe order of thread allocation, in incrementing thread order. As shown,at time T=0, thread 0 is allocated; at time T=1, thread 1 is allocated;at time T=2, thread 2 is allocated; at time T=3, thread 3 is allocated;and at time T=4, thread 4 is allocated. Threads 4, 2, 0 and 1 arerequested to order func0 type events and are listed in the order thatthey are received by ESMO 1602. As shown, ESMO 1602 receives a func0event request from thread 4 at time T=5, a func0 event request fromthread 2 at time T=7, a func0 event request from thread 0 at time T=8,and a func0 event request from thread 1 at time T=9.

As shown, ESM1 1604 receives a func1 event request from thread 3 at timeT=6. Threads scheduled by ESMO 1602 are shown as threads 0′, 1′, 2′ and4′. ESMO 1602 schedules func0 events on threads 0, 1 and 2 however, ESMO1602 cannot schedule a func0 event for thread 4 until thread 3 isde-allocated, or thread 3 requests a func0 event, such that thread 4becomes the oldest unscheduled thread for ESMO 1602. Threads scheduledby ESMO 1602 might be employed to request func1 events. As shown in theexample of FIG. 16, ESM1 1604 receives a func1 event request from thread1′ at time T=11, a func1 event request from thread 1′ at time T=11, anda func1 event request from thread 1′ at time T=11. Threads scheduled byESM1 1604 are shown as threads 0″, 1″, 2″ and 3″. ESM1 1604 processesthese requests and schedules the func1 events in the thread start order,shown as threads 0″ (at time T=14), 1″ (at time T=15), 2″ (at time T=16)and 3″ (at time T=17). In this example, once ESM1 1604 schedules threads0″, 1″, 2″ and 3″, the threads are complete and can be de-allocated.Thus, as shown, de-allocate events are received by TSM 1500, forexample, for thread 0″ at time T=15, for thread 1″ at time T=16, forthread 2″ at time T=17, for thread 3″ at time T=18,and for thread 4′ attime T=20. TSM 1500 broadcasts the de-allocation of thread 3″ at timeT=18 allowing ESMO 1602 to schedule thread 4 at time T=19. Thus, ESMOand ESM1 have scheduled the func0 and func1 events respectively inthread start order.

As described with regard to FIG. 15, function requests might arrive toone of ESMs 1502(1)-1502(Y) in any order associated with a thread, forexample by event_in signal 1512(1), but the ESMs reorder the functionrequests to be issued in the thread start order, for example by eventout signal 1514(1).

Thus, as described herein, embodiments of the present invention providea packet classifier for a network processor that generates taskscorresponding to each received packet. The packet classifier includes ascheduler to generate a thread of contexts for each task received by thepacket classifier from a plurality of processing modules of the networkprocessor. The scheduler includes one or more output queues totemporarily store contexts. Each thread corresponds to an order ofinstructions applied to the corresponding packet, and includes anidentifier of a corresponding one of the output queues. The schedulersends the contexts to a multi-thread instruction engine that processesthe threads. An arbiter selects one of the output queues in order toprovide output packets to the multi-thread instruction engine, theoutput packets associated with a corresponding thread of contexts. Eachoutput queue transmits output packets corresponding to a given threadcontiguously in the order in which the threads started.

While the exemplary embodiments of the present invention have beendescribed with respect to processing blocks in a software program,including possible implementation as a digital signal processor,micro-controller, or general purpose computer, the present invention isnot so limited. As would be apparent to one skilled in the art, variousfunctions of software might also be implemented as processes ofcircuits. Such circuits might be employed in, for example, a singleintegrated circuit, a multi-chip module, a single card, or a multi-cardcircuit pack.

The present invention can be embodied in the form of methods andapparatuses for practicing those methods. The present invention can alsobe embodied in the form of program code embodied in tangible media, suchas magnetic recording media, optical recording media, solid statememory, floppy diskettes, CD-ROMs, hard drives, or any othernon-transitory machine-readable storage medium, wherein, when theprogram code is loaded into and executed by a machine, such as acomputer, the machine becomes an apparatus for practicing the invention.The present invention can also be embodied in the form of program code,for example, whether stored in a non-transitory machine-readable storagemedium, loaded into and/or executed by a machine, or transmitted oversome transmission medium or carrier, such as over electrical wiring orcabling, through fiber optics, or via electromagnetic radiation,wherein, when the program code is loaded into and executed by a machine,such as a computer, the machine becomes an apparatus for practicing theinvention. When implemented on a general-purpose processor, the programcode segments combine with the processor to provide a unique device thatoperates analogously to specific logic circuits. The present inventioncan also be embodied in the form of a bitstream or other sequence ofsignal values electrically or optically transmitted through a medium,stored magnetic-field variations in a magnetic recording medium, etc.,generated using a method and/or an apparatus of the present invention.

It should be understood that the steps of the exemplary methods setforth herein are not necessarily required to be performed in the orderdescribed, and the order of the steps of such methods should beunderstood to be merely exemplary. Likewise, additional steps might beincluded in such methods, and certain steps might be omitted orcombined, in methods consistent with various embodiments of the presentinvention.

As used herein in reference to an element and a standard, the term“compatible” means that the element communicates with other elements ina manner wholly or partially specified by the standard, and would berecognized by other elements as sufficiently capable of communicatingwith the other elements in the manner specified by the standard. Thecompatible element does not need to operate internally in a mannerspecified by the standard.

Also for purposes of this description, the terms “couple,” “coupling,”“coupled,” “connect,” “connecting,” or “connected” refer to any mannerknown in the art or later developed in which energy is allowed to betransferred between two or more elements, and the interposition of oneor more additional elements is contemplated, although not required.Conversely, the terms “directly coupled,” “directly connected,” etc.,imply the absence of such additional elements. Signals and correspondingnodes or ports might be referred to by the same name and areinterchangeable for purposes here.

It will be further understood that various changes in the details,materials, and arrangements of the parts which have been described andillustrated in order to explain the nature of this invention might bemade by those skilled in the art without departing from the scope of theinvention as expressed in the following claims.

We claim:
 1. A packet classifier for a network processor having aplurality of processing modules, wherein the network processor generatesone or more tasks corresponding to each of a plurality of receivedpackets, the packet processor comprising: a scheduler configured to (i)generate a thread of one or more contexts for each task received by thepacket classifier, wherein the thread corresponds to an order ofinstructions applied to the corresponding packet, and (ii) send thecontexts to a multi-thread instruction engine configured to process theone or more threads received from the scheduler, wherein the contextsare temporarily stored in one or more output queues of the scheduler;wherein each thread includes an identifier of a corresponding one of theone or more output queues; an arbiter configured to select one of theone or more output queues in order to provide output packets to themulti-thread instruction engine, one or more of the output packetsassociated with a corresponding thread of contexts; wherein each outputqueue transmits output packets corresponding to a given threadcontiguously in the order in which the threads started, wherein thescheduler comprises: a completion list having one or more linked lists,each linked list corresponding to the one or more output queues, whereinthe scheduler inserts an entry in the completion list corresponding toeach received task, the thread entries stored in order in which a firsttask of each thread is are received; wherein each entry in thecompletion list comprises an identifier of a corresponding thread, alink to a subsequent entry in the completion list corresponding to thecorresponding thread, and an indication if the entry is a last entry ofthe corresponding thread; wherein an oldest unspecified list specifiesan order in which a first context of each thread is received by thescheduler; and the scheduler further configured to (i) track which ofthe one or more output queues corresponds to each thread with (1) aqueue table and (2) a per-thread table, the queue table identifying anoutput queue corresponding to each thread and the per-thread tablehaving one or more entries corresponding to each of the one or moreoutput queues, each per-thread table entry having a head pointer and atail pointer of the linked list of each entry in the completion listcorresponding to the given thread, (ii) assign one of the one or moreoutput queues to the thread corresponding to an oldest entry of theoldest unspecified list, and (iii) remove the oldest entry from theoldest unspecified list.
 2. The packet classifier of claim 1, whereinthe scheduler is further configured to: select a non-empty one of theone or more output queues to provide output packets corresponding to athread.
 3. The packet classifier of claim 2, wherein the scheduler isfurther configured to: transmit all output packets corresponding to athread until the scheduler receives an indicator that a last outputpacket of a thread is transmitted, wherein output packets aretransmitted in an order in which corresponding input packets arereceived by the network processor.
 4. The apparatus of claim 1, whereinthe network processor is implemented in an integrated circuit.
 5. Amethod of processing received packets by a packet classifier of anetwork processor having a plurality of processing modules, the methodcomprising: generating, by at least one of the plurality of processingmodules, one or more tasks corresponding to each of a plurality ofreceived packets; generating, by a scheduler of the packet classifier, athread of one or more contexts for each task received by the packetclassifier, wherein the thread corresponds to an order of instructionsapplied to the corresponding packet; storing, by the scheduler, thecontexts in one or more output queues; selecting, by an arbiter, acorresponding one of the one or more output queues, to provide one ormore output packets to a multi-thread instruction engine of the networkprocessor wherein one or more output packets correspond to a thread ofcontexts; wherein each output queue is configured to transmit outputpackets corresponding to a given thread contiguously in the order inwhich the threads were started; storing, in a completion list, one ormore linked lists, each linked list corresponding to the one or moreoutput queues; inserting, by the scheduler, an entry in the completionlist corresponding to each received task, the thread entries stored inorder in which a first task of each thread is are received; wherein eachentry in the completion list comprises an identifier of a correspondingthread, a link to a subsequent entry in the completion listcorresponding to the corresponding thread, and an indication if theentry is a last entry of the corresponding thread; tracking, by a queuetable, which of the one or more output queues corresponds to eachthread; storing ,by a per-thread table having one or more entriescorresponding to each of the one or more output queues, a head pointerand a tail pointer of the linked list of each entry in the completionlist corresponding to the given thread; tracking, by an oldestunspecified list, an order in which a first context of each thread isreceived by the scheduler, assigning, by the scheduler, one of the oneor more output queues to the thread corresponding to an oldest entry ofthe oldest unspecified list; and removing, by the scheduler, the oldestentry from the oldest unspecified list.
 6. The method of claim 5, themethod further comprising: selecting a non-empty one of the one or moreoutput queues to provide output packets corresponding to a thread. 7.The method of claim 6, the method further comprising: transmitting alloutput packets corresponding to a thread until receiving, by thescheduler, an indication that a last output packet of a thread istransmitted, whereby output packets are transmitted in an order in whichcorresponding input packets are received by the network processor.
 8. Anon-transitory machine-readable medium, having encoded thereon programcode, wherein, when the program code is executed by a machine, themachine implements a method of processing received packets by a packetclassifier of a network processor having a plurality of processingmodules, the method comprising: generating, by at least one of theplurality of processing modules, one or more tasks corresponding to eachof a plurality of received packets; generating, by a scheduler of thepacket classifier, a thread of one or more contexts for each taskreceived by the packet classifier, wherein the thread corresponds to anorder of instructions applied to the corresponding packet; storing, bythe scheduler, the contexts in one or more output queues; selecting, byan arbiter, a corresponding one of the one or more output queues, toprovide one or more output packets to a multi-thread instruction engineof the network processor wherein one or more output packets correspondto a thread of contexts; wherein each output queue is configured totransmit output packets corresponding to a given thread contiguously inthe order in which the threads were started; storing, in a completionlist, one or more linked lists, each linked list corresponding to theone or more output queues; inserting, by the scheduler, an entry in thecompletion list corresponding to each received task, the thread entriesstored in order in which a first task of each thread is are received;wherein each entry in the completion list comprises an identifier of acorresponding thread, a link to a subsequent entry in the completionlist corresponding to the corresponding thread, and an indication if theentry is a last entry of the corresponding thread; tracking, by a queuetable, which of the one or more output queues corresponds to eachthread; storing, by a per-thread table having one or more entriescorresponding to each of the one or more output queues, a head pointerand a tail pointer of the linked list of each entry in the completionlist corresponding to the given thread; tracking, by an oldestunspecified list, an order in which a first context of each thread isreceived by the scheduler, assigning, by the scheduler, one of the oneor more output queues to the thread corresponding to an oldest entry ofthe oldest unspecified list; and removing, by entry r from the oldestunspecified list.
 9. The machine-readable medium of claim 8, the methodfurther comprising: selecting a non-empty one of the one or more outputqueues to provide output packets corresponding to a thread.
 10. Themachine-readable medium of claim 9, the method further comprising:transmitting all output packets corresponding to a thread untilreceiving, by the scheduler, an indication that a last output packet ofa thread is transmitted, whereby output packets are transmitted in anorder in which corresponding input packets are received by the networkprocessor.